package com.baidu.foodrecipe.data.local

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.baidu.foodrecipe.data.local.entity.FavoriteEntity
import com.baidu.foodrecipe.data.local.entity.RecipesEntity
import kotlinx.coroutines.flow.Flow

@Dao
interface RecipesDao {
    /*
     查询所有的食谱数据
     */
    @Query("select * from recipes_table")
    suspend fun getRecipes(): List<RecipesEntity>

    /*
    插入新的数据
    如果数据已经存在，会替换
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertRecipe(entity: RecipesEntity)

    /*
    查询所有的收藏食谱数据
     */
    @Query("select * from favorites_table")
    fun getFavoriteRecipes(): Flow<List<FavoriteEntity>>

    /*
    插入新的收藏食谱数据
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertFavoriteRecipe(entity: FavoriteEntity)

    @Delete
    suspend fun removeFavoriteRecipe(entity: FavoriteEntity)

    @Query("delete from favorites_table")
    suspend fun deleteAllFavoriteRecipes()
}









